import json
from aip import AipBodyAnalysis


class BaiduDemo():
    def __init__(self, conffile):
        data = self.get_file_content(conffile)
        jdata = json.loads(data)
        self.client = AipBodyAnalysis(jdata["appid"], jdata["apikey"], jdata["seckey"])

    def get_file_content(self, file):
        with open(file, 'rb') as fp:
            return fp.read()

    def body_analysis(self, imagefile):
        data = self.get_file_content(imagefile)
        
        out = self.client.bodyAnalysis(data)
        print("out: ", out)

    def body_attr(self, imagefile):
        data = self.get_file_content(imagefile)
        out = self.client.bodyAttr(data)
        print("out: ", out)